Reading Inputs Using Buffered Reader
Oct 13, 2014
I am trying to read the following input (which will be inputted by the user when run) using the BufferedReader approach:
1
*** * * * *** *** *** ***
* * * * * * * * *
* * * *** *** *** *** ***
* * * * * * * * *
*** * * *** *** *** ***
I am reading each line of the input one line at a time and incrementally storing four char positions into an array, so i am able to hold a vertical representation of each column. I.e. column 1 will be stored in array[0].
The problem with my code is that is does not read the last line of the input, it reads all the other inputs before it but just refuses to read the last line and execute the procedure of storing the characters.
Code:
public void defuseBomb(){
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String asciiLine = reader.readLine()+ " ";
int digit = (asciiLine.length())/4;
[Code] .....
View Replies
Mar 7, 2010
I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.
Here is the code I have so far:
public static BufferedImage rotate(BufferedImage img) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage newImage = new BufferedImage(width, height, img.getType());
Graphics2D g2 = newImage.createGraphics();
g2.rotate(Math.toRadians(90), w/2, h/2);
g2.drawImage(img,null,0,0);
return newImage;
}
This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.
View Replies
View Related
Oct 31, 2014
I am writing a java program that takes a FROM image, a TO image, and a ratio (this is a slide bar in the GUI). Here's my code:
Java Code:
public static BufferedImage rollUp (BufferedImage from,
BufferedImage to,
double ratio) {
BufferedImage finalBufferedImage = new BufferedImage(from.getWidth(),
from.getHeight(),
from.getType());
int packedColor = 0;
for (int r = 0; r < from.getHeight(); ++r) {
for (int c = 0; c < from.getWidth() ; ++c) {
[code]...
So from 0 to 1 (ratio is a double between 0 and 1) the image will "roll up". The effect works completely in the GUI, but the console freaks out at about 0.33 ratio.. This program runs for testing in a class Main and uses a class Splittinimage.. this method is in class TwixPix. When the main class is run, a box pops up with a combo box and a slider. You pick an effect (in this case, roll up) and then slide the slider to set the ratio. The image below those two things performs the effect that was selected. Imagine a PowerPoint presentation slide effect.
View Replies
View Related
Apr 22, 2015
The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value). My assignment is to get a solved sudoku for these values:
//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}
My current code
public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on
[Code] .....
View Replies
View Related