• 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

    • Movavi Video Editor 25.9.0 by Razvan Serea With Movavi Video Editor, you can either enhance your video files with two or three simple steps, or turn them into something completely new. Create your own movies using multiple filters, transitions, and special effects: show multiple videos on one screen with the Picture in picture effect or change the background with the Chroma Key effect, imitate the camera zoom or make your video look like an old-style movie. Adjust video parameters such as brightness, contrast and colors. Stabilize shaky footage, improve video quality and remove defects. Create video presentations, tutorials or educational videos: add titles and record your own narration to create a video with voiceover. Import video from any source: TV-tuner, webcam, camcorder, or VHS. Drop multiple media files onto a timeline and let your imagination do the rest! Features at a glance: Video and audio editing on a timeline Edit, enhance videos Add background music Apply titles and effects Image quality improvement Hollywood-worthy effects High-grade titles and fades Digitize VHS tapes, record video from TV tuners Stabilize any shaky sections Support for a wide range of formats Prepare your videos for uploading to YouTube, Facebook, Vimeo, or any other website New in Movavi Video Editor 2025: Revamped timeline for easier editing The new timeline is now clearer and more streamlined. Get your projects done faster and have more fun with anything – from short vids for socials to longer family movies. Frame-precise cuts in a click Give your videos a sharper look with the new Blade tool. Easily make precise cuts and create eye-catching montages like your favorite bloggers. Pro-quality color correction Get next-level color correction with the same simplicity. Boost colors in a snap and make more viewers fall in love with your videos. AI motion tracking Enhance reality in your videos with additional moving graphics. Just click, and AI will quickly attach any photos, videos, emojis, or memes to objects in your footage. Perfect-match overlay effects Now each overlay effect has 13 blending modes to choose from. Try each of them with the press of a button and pick the one that fits your video perfectly. Best video effects – at your fingertips Create awesome videos in any style with our huge collection of professionally designed effects. Now you can try them all right away, right in the app. Movavi Video Editor 25.9.0 changelog: New Copy effects from one clip to another in a snap. Just right-click the clip → Clip effects → Copy effects. Then right-click again to paste. Try it once, and it might just become your new favorite feature. Improvements Enjoy speedier, smoother previews – now up to 20% faster! Hover over any clip to see the difference. Especially handy when you’ve got a load of clips on the timeline. Speed up editing with new keyboard shortcuts. Ctrl + Z to undo, Ctrl + scroll to zoom the timeline. You’ll find the full list in the Help menu. Fixed issues Some under-the-hood improvements that’ll be useful for faster content creation. Download: Movavi Video Editor Plus 25.9.0 | 5.1 MB (Shareware) View: Movavi Video Editor Plus Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I don't disagree, but I am also not absolving Microsoft. Data protection is the user's responsibility AND OneDrive shouldn't arbitrarily lockout paying users with no way to get support. Again, both statements can be true at the same time. I doubt you mean to imply it is okay for companies to violate their SLAs and screw over their customers. Assuming you don't think that, then we have no disagreement my friend.
    • Also, Microsoft locks Windows 11 user out, shows how easy losing data from forced encryption is The reddit post has nothing to do with Windows 11 or 'Forced' Encryption, at all, reading the thread a guy has uploaded a load of files, deleted the source, tripped the ToS for some reason and been locked out The guy could have been using Windows 7 box with no drive encryption. A more accurate headline would be User with no backup looses data
    • I've been using Microsoft cloud storage since before it was named OneDrive. Though typically only upload the following items. Game Screenshots of like crashes if its a driving game, or occasionally a Video recorded with GameDVR All Purchased Music from former Microsoft App store when they offered music during Windows 8.1, Xbox/Groove Music days, in additon to the 30 Free Albums Christmas 2024 for using a Windows Phone at the time. Of course everything is also backed up on 3 external hard drives as well. and albums that would be hard to replace, also uploaded to GoogleDrive, ((though can't upload all of it to Google drive, as not enough space there to lol)) Been using Microsoft Hotmail & Outlook email ever since first released Hotmail originally signed up April 1998 during high school class Outlook.com email converted to when first launched many years ago
  • Recent Achievements

    • Week One Done
      Rhydderch earned a badge
      Week One Done
    • Experienced
      dismuter went up a rank
      Experienced
    • One Month Later
      mevinyavin earned a badge
      One Month Later
    • Week One Done
      rozermack875 earned a badge
      Week One Done
    • Week One Done
      oneworldtechnologies earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      699
    2. 2
      ATLien_0
      272
    3. 3
      Michael Scrip
      214
    4. 4
      +FloatingFatMan
      186
    5. 5
      Steven P.
      144
  • Tell a friend

    Love Neowin? Tell a friend!