K very simple question which i hope can be answered just as simply.
New to java.
Trying to read an ineger and assign it to a variable.
using c consle.
For example:
------------------
int age; //???
c.print("Age: ");
//read age
c.println("Your "+age+"years old");
------------------------------------
Easy enough?
Thanks
public static void main(String[] args) {
Scanner cin = new Scanner(system.in);
System.out.println("Age: ");
int age = cin.nextInt();
System.out.println("You are " + age + " years old.\n");
return;
}
#include <stdio.h>
int main(void)
{
puts("You\'re wrong!");
return 0;
}
The fuck they can't.
Name:
Anonymous2006-09-26 4:42
>>12
Why are you escaping the '? This isn't perl or python.
Name:
Anonymous2006-09-26 5:14
Java is awesome for it's simpleness :)
import java.io.*;
class ReadAge {
public static void main (String[] arg) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
System.out.println("You're " + a + " years old");
}
}
Name:
Anonymous2006-09-26 5:26
>>4 ..since computers can't use contractions.
What!?
>>13
You don't have to in Perl or Python either, unless you open quotes with ' .
Here's the homework, fixed: print "Enter your age"
age = int(raw_input())
print "You're a fag either way"