T
teshmee
hello,
in fact i need to write a program, that accepts an input from the user
and 1 is being added to the value inputted 5 times.. i know i should
use FOR.
import java.io.*;
import java.util.*;
public class Test2
{
public static void main(String[] args) throws Exception
{
int userInput;
System.out.println("Please enter a Number:");
userInput = (int)System.in.read();
for (int i =1; i<6; i++)
System.out.println(userInput + i);
}
}
this is the code i wrote, but the result is wrong as i tried the
pseudocode and when tested with this pseudocode:
1. START
2. PRINT ‘Enter number’
3. INPUT Number
4. Result = Number
5. FOR I=1; I<6; I= ++
Result = Result + 1
PRINT Result
ENDFOR
6. STOP
when i tested using 10 as the value inputted,
i got: 11,12,13,14,15 as the result
but with the java code it is not the case..
Can anybody please help me find my error.
regards,
teshmee.
in fact i need to write a program, that accepts an input from the user
and 1 is being added to the value inputted 5 times.. i know i should
use FOR.
import java.io.*;
import java.util.*;
public class Test2
{
public static void main(String[] args) throws Exception
{
int userInput;
System.out.println("Please enter a Number:");
userInput = (int)System.in.read();
for (int i =1; i<6; i++)
System.out.println(userInput + i);
}
}
this is the code i wrote, but the result is wrong as i tried the
pseudocode and when tested with this pseudocode:
1. START
2. PRINT ‘Enter number’
3. INPUT Number
4. Result = Number
5. FOR I=1; I<6; I= ++
Result = Result + 1
PRINT Result
ENDFOR
6. STOP
when i tested using 10 as the value inputted,
i got: 11,12,13,14,15 as the result
but with the java code it is not the case..
Can anybody please help me find my error.
regards,
teshmee.