• 0

[Java] integer arithmetic


Question

Yeah well, Ive been taking an Intro to programming class, and ive been reading up on stuff, because the teacher doesn't know much himself :no: . And he gave us an assignment, none of us really knew what to do.

I know this is a beginner question, but I am one.

---

Exercise 2 --- Cents to Dollars

Write a program that reads in a number of cents. The program will write out the number of dollars and cents, like this:

D:\users\default>java Dollars

Input the cents:

324

That is 3 dollars and 24 cents.

(For this program you will use integer arithmetic and will need to avoid floating point arithmetic. Review the integer remainder operator % if you are unsure how to proceed.)

---

I have gotten this far, but am not sure what variables to put in

import java.io.*;
class Echo
{
  public static void main (String[] args) throws IOException
  {
	InputStreamReader inStream = 
		new InputStreamReader( System.in );
	BufferedReader stdin = 
		new BufferedReader( inStream );

	String inData;

	System.out.println("Numberents:");
	inData = stdin.readLine();

	System.out.println("You:" + inData );
  }
}

Link to comment
https://www.neowin.net/forum/topic/459446-java-integer-arithmetic/
Share on other sites

8 answers to this question

Recommended Posts

  • 0
  Mclaren LM said:

Yeah well, Ive been taking an Intro to programming class, and ive been reading up on stuff, because the teacher doesn't know much himself :no: . And he gave us an assignment, none of us really knew what to do.

I know this is a beginner question, but I am one.

---

Exercise 2 --- Cents to Dollars

Write a program that reads in a number of cents. The program will write out the number of dollars and cents, like this:

D:\users\default>java Dollars

Input the cents:

324

That is 3 dollars and 24 cents.

(For this program you will use integer arithmetic and will need to avoid floating point arithmetic. Review the integer remainder operator % if you are unsure how to proceed.)

---

I have gotten this far, but am not sure what variables to put in

import java.io.*;
class Echo
{
  public static void main (String[] args) throws IOException
  {
	InputStreamReader inStream = 
		new InputStreamReader( System.in );
	BufferedReader stdin = 
		new BufferedReader( inStream );

	String inData;

	System.out.println("Numberents:");
	inData = stdin.readLine();

	System.out.println("You:" + inData );
  }
}

int dollar = Integer.parseInt(inData)/100;

int cent = Integer.parseInt(inData) % 100;

System.out.println("That"+dollar+" dollars and "+cent+" cents.");

  • 0

Thanks, I still get an error saying this:

C:\Documents and Settings\Wootbiker\My Documents\JAvaFiles\ex1.java:6: cannot find symbol

symbol : variable inData

location: class ex1

int dollar = Integer.parseInt(inData)/100;

^

C:\Documents and Settings\Wootbiker\My Documents\JAvaFiles\ex1.java:7: cannot find symbol

symbol : variable inData

location: class ex1

int cent = Integer.parseInt(inData) % 100;

^

2 errors

Process completed.

Edited by Mclaren LM
  • 0

import java.io.*;
class Echo
{
  public static void main (String[] args) throws IOException
  {
	InputStreamReader inStream =
		new InputStreamReader( System.in );
	BufferedReader stdin =
		new BufferedReader( inStream );

	String inData;

	System.out.println("Numberents:");
	inData = stdin.readLine();

	int dollar = Integer.parseInt(inData)/100;
int cent = Integer.parseInt(inData) % 100;

System.out.println("That+dollar+" dollars and "+cent+" cents.");
  }
}

Try this

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Crowdstrike the same service provider that caused millions of in damages? I hate disliking a company for a singular failure but they really screwed up.
    • I see you subscribe to the Linux/macOS approach to winning over converts...
    • As we get closer to October 2025 and the end of Windows 10 support, Windows 11 will pick up its pace and soon become the most popular desktop operating system worldwide. That's an assertion. It's also quite possible that the only growth will come from attrition as people and companies buy new machines that only come with Win11. It's also possible that we'll get a literal repeat of Win XP and Win 7, where a large number of users just waited until Microsoft gave in and fixed the core problems that the consumers were complaining about in Win Vista and Win 8 when they released Win 7 and Win 10.
    • It's significant growth for Linux considering the market share, so it could have had that effect I described.
    • Microsoft and Crowdstrike announce partnership on threat actor naming by Pradeep Viswanathan Whenever a cyberattack is discovered, companies disclose it to the public and assign it a unique name based on their internal procedures. Unfortunately, this leads to inconsistencies, as each company has its own naming conventions. As a result, the same threat actor behind a cyberattack may end up with multiple names, causing delays and confusion in response efforts. For example, a threat actor that Microsoft refers to as Midnight Blizzard might be known as Cozy Bear, APT29, or UNC2452 by other security vendors. To address this issue, Microsoft and CrowdStrike are teaming up. These companies will align their individual threat actor taxonomies to help security professionals respond to cyberattacks with greater clarity and confidence. It’s important to note that Microsoft and CrowdStrike are not attempting to create a single naming standard. Instead, they are releasing a mapping that lists common threat actors tracked by both companies, matched according to their respective taxonomies. The mapping also includes corresponding aliases from each group’s naming system. You can view the joint threat actor mapping by Microsoft and CrowdStrike here. Although this threat actor taxonomy mapping is a joint effort between Microsoft and CrowdStrike, Google/Mandiant and Palo Alto Networks' Unit 42 are expected to contribute to this initiative in the future. Vasu Jakkal, Corporate Vice President of Microsoft Security, wrote the following about this collaboration with CrowdStrike: As more organizations join this initiative, the collective defense against cyber threats will undoubtedly be improved.
  • Recent Achievements

    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
    • Reacting Well
      sultangris earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      173
    2. 2
      ATLien_0
      125
    3. 3
      snowy owl
      122
    4. 4
      Xenon
      116
    5. 5
      +Edouard
      93
  • Tell a friend

    Love Neowin? Tell a friend!